package com.example.myapplication;

import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import androidx.appcompat.app.AppCompatActivity;

import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.ExecutionException;

public class AddItemActivity extends AppCompatActivity implements View.OnClickListener{

    private EditText mEditText3;
    private EditText mEditText4;
    private EditText mEditText5;
    private EditText mEditText6;
    private EditText mEditText7;
    private EditText mEditText8;
    private Button mButton;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_add_item);
        mEditText3 = (EditText) findViewById(R.id.editText3);
        mEditText4 = (EditText) findViewById(R.id.editText4);
        mEditText5 = (EditText) findViewById(R.id.editText5);
        mEditText6 = (EditText) findViewById(R.id.editText6);
        mEditText7 = (EditText) findViewById(R.id.editText7);
        mEditText8 = (EditText) findViewById(R.id.editText8);
        mButton = (Button) findViewById(R.id.button);

        mButton.setOnClickListener(this);

    }

    @Override
    public void onClick(View v) {
        String name = mEditText3.getText().toString();
        String itemDesc = mEditText4.getText().toString();
        String itemRemark = mEditText5.getText().toString();
        String itemPrice = mEditText6.getText().toString();
        String time = mEditText7.getText().toString();
        String kindId = mEditText8.getText().toString();
        //数据打包
        Map<String,String> map = new HashMap<>();
        map.put("itemName",name);
        map.put("itemDesc",itemDesc);
        map.put("itemRemark",itemRemark);
        map.put("initPrice",itemPrice);
        map.put("avail",time);
        map.put("kindId",kindId);

        try {
            String result = OkHttpUtil.postRequest("http://172.18.85.254:8080/auction/api/items",map);
            System.out.println(result);
        } catch (ExecutionException e) {
            e.printStackTrace();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
}
